package cn.ilovese.collect.serviceimpl.report;

import cn.ilovese.collect.datamapper.coordination.CoordinationAbilityMapper;
import cn.ilovese.collect.controller.socket.WebSocketServer;
import cn.ilovese.collect.datamapper.coordination.CoordinationRankingMapper;
import cn.ilovese.collect.datamapper.report.*;
import cn.ilovese.collect.datamapper.similarity.PicSimilarityMapper;
import cn.ilovese.collect.datamapper.similarity.TextSimilarityMapper;
import cn.ilovese.collect.datamapper.task.TaskMapper;
import cn.ilovese.collect.datamapper.user.ActivityMapper;
import cn.ilovese.collect.datamapper.user.UserMapper;
import cn.ilovese.collect.datamapper.work.WorkMapper;
import cn.ilovese.collect.po.coordination.CoordinationAbility;
import cn.ilovese.collect.datamapper.workermessage.WorkerMessageMapper;
import cn.ilovese.collect.po.coordination.CoordinationRanking;
import cn.ilovese.collect.po.report.*;
import cn.ilovese.collect.po.similarity.PicSimilarity;
import cn.ilovese.collect.po.similarity.TextSimilarity;
import cn.ilovese.collect.po.task.Task;
import cn.ilovese.collect.po.user.Activity;
import cn.ilovese.collect.po.user.User;
import cn.ilovese.collect.po.work.Work;
import cn.ilovese.collect.po.workermessage.WorkerMessage;
import cn.ilovese.collect.service.report.ReportService;
import cn.ilovese.collect.service.report.similaritystrategy.PictureSimilarityStrategy;
import cn.ilovese.collect.service.report.similaritystrategy.TextSimilarityStrategy;
import cn.ilovese.collect.serviceimpl.report.similaritystrategy.*;
import cn.ilovese.collect.util.Constant;
import cn.ilovese.collect.vo.ResultVO;
import cn.ilovese.collect.vo.report.*;
import cn.ilovese.collect.vo.similarity.ReportSimilarityVO;
import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.corpus.tag.Nature;
import com.hankcs.hanlp.seg.common.Term;
import javafx.util.Pair;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@CacheConfig(cacheNames = "report",cacheManager = "cacheManager")
public class ReportServiceImpl implements ReportService {

    // @Resource标识特定的目标组件，你们自己添加，类似软工二
    // @Autowired装载java bean，用于set方法，你们自己添加，类似软工二
    //注意在这里添加每个实现方法的说明注释，类似以下
    /**
     * 这个方法干了什么
     *
     * @param 参数1 解释
     * @param 参数2 解释
     * ......
     * @return 返回值解释
     */

    @Resource
    ReportMapper reportMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    TaskMapper taskMapper;
    @Resource
    WorkMapper workMapper;
    @Resource
    TFIDFSimilarityMapper tfidfSimilarityMapper;
    @Resource
    CoordinationMapper coordinationMapper;
    @Resource
    TextSimilarityMapper textSimilarityMapper;
    @Resource
    PicSimilarityMapper picSimilarityMapper;
    @Resource
    CoordinationAbilityMapper coordinationAbilityMapper;
    @Resource
    CoordinationRankingMapper coordinationRankingMapper;
    @Resource
    SimHashStrategy simHashStrategy;
    @Resource
    TFIDFStrategy tfidfStrategy;
    @Resource
    Word2VecStrategy word2VecStrategy;
    @Resource
    WorkerMessageMapper workerMessageMapper;
    @Resource
    ScoreSimilarityMapper scoreSimilarityMapper;
    @Resource
    ScoreMapper scoreMapper;

    @Resource
    ReportVisitMapper reportVisitMapper;

    @Resource
    ActivityMapper activityMapper;

    /**
     * 将报告写入数据库
     * @param reportVO
     * @return 返回写数据库的结果
     */
    @Override
    public ResultVO<ReportVO> createReport(ReportFormVO reportVO) {
        Report report=new Report(reportVO);
        report.setSubmitTime(new Date());
        if(reportMapper.insert(report) > 0) {
            ReportVO res = new ReportVO(report);

            Integer taskid = report.getTaskId();
            Integer userid = report.getUserId();
            Task task = taskMapper.selectByPrimaryKey(taskid);
            System.out.println();
            String username = userMapper.selectByPrimaryKey(userid).getUsername();
            String type = task.getType();
            String taskname = task.getTaskName();

            //给返回的VO对象赋值属性
            res.setTaskname(taskname);
            res.setType(type);
            res.setWorkername(username);

            //将这个work的status修改为2
            Work work = workMapper.selectByWorkerAndTask(taskid, userid);
            work.setStatus(2);
            workMapper.updateByPrimaryKey(work);


            //向这个task的reportnum中增加1
//            System.out.println(task.getReportNumber() + 1);
            int currNum = task.getReportNumber();
            task.setReportNumber(currNum + 1);
            taskMapper.updateByPrimaryKey(task);


            //更新ifidf词频数据库
            tfidfStrategy.updateTFIDF(reportVO);

            Date nowTime = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String nowDate = sdf.format(nowTime);
            Activity loginRecord=activityMapper.selectByUserIdAndLoginDate(userid,nowDate);
            activityMapper.increaseActivityByUserid(userid,5,nowDate);
            return new ResultVO<>(Constant.REQUEST_SUCCESS, "报告提交成功!", res);
        }
        return new ResultVO<>(Constant.REQUEST_FAIL, "服务器错误");
    }

    /**
     *
     * @param taskId
     * @return 返回某个task对应的所有报告列表
     */
    @Override
    public ResultVO<List<ReportWithWorkerNameVO>> getReportList(Integer taskId) {
        List<ReportWithWorkerNameVO> ret = new ArrayList<>();
        List<Report> reportList = reportMapper.selectByTaskId(taskId);
        Task task = taskMapper.selectByPrimaryKey(taskId);
        String taskname = task.getTaskName();
        String type = task.getType();
        if(reportList.size() == 0)
            return new ResultVO<>(Constant.REQUEST_FAIL,"获取报告列表失败");
        //这里返回报告的时候需要判断报告是否计算完成
        //如果不是第一个报告并且没有计算完成就跳过不反悔
        for(Report report: reportList){
            Integer id = report.getId();
            //判断是否是第一个报告
            List<Report> tempList = reportMapper.selectOtherReport(taskId,id);
            //说明不是第一个报告
            if(tempList.size() != 0){
                List<PicSimilarity> picSimilarityList = picSimilarityMapper.selectByFirstId(id);
                //说明这个报告不是该task的第一个报告，并且相似度没有计算完成
                if(picSimilarityList  == null || picSimilarityList.size() == 0){
                    continue;
                }
            }
            ReportVO temp = new ReportVO(report);
            Integer workerid = report.getUserId();
            temp.setWorkername(userMapper.selectByPrimaryKey(workerid).getUsername());
            temp.setTaskname(taskname);
            temp.setType(type);
            ReportWithWorkerNameVO reportWithWorkerNameVO = new ReportWithWorkerNameVO(temp,workerid);
            ret.add(reportWithWorkerNameVO);
        }
        return new ResultVO<>(Constant.REQUEST_SUCCESS, "获取报告列表成功!",ret);
    }

    /**
     * @param reportId
     * @return 返回某个具体报告
     */
    @Override
    public ResultVO<ReportVO> getReport(Integer reportId) {
        Report report=reportMapper.selectByPrimaryKey(reportId);
        if(report == null)
            return new ResultVO<>(Constant.REQUEST_FAIL, "获取报告详情失败");
        ReportVO res = new ReportVO(report);
        String username = userMapper.selectByPrimaryKey(report.getUserId()).getUsername();
        Integer taskid = report.getTaskId();
        Task task;
        //说明是子报告
        if(taskid == null){
            Integer fatherid = coordinationMapper.selectByChildrenId(reportId).getFatherId();
            task = taskMapper.selectByPrimaryKey(reportMapper.selectByPrimaryKey(fatherid).getTaskId());
        }
        else{
            task = taskMapper.selectByPrimaryKey(taskid);
        }
        System.out.println(task);
        String taskname = task.getTaskName();
        String type = task.getType();
        res.setType(type);
        res.setTaskname(taskname);
        res.setWorkername(username);
        return new ResultVO<>(Constant.REQUEST_SUCCESS, "获取报告详情成功", res);
    }

    @Override
    public ResultVO<ReportWithSimilarityVO> getReportByReportId(Integer reportId) throws IOException {
        Report report = reportMapper.selectByPrimaryKey(reportId);
        if(report == null)
            return new ResultVO<>(Constant.REQUEST_FAIL, "没有找到对应的报告！");
        return getReportByWorker(report);
    }
    @Override
    public ResultVO<ReportWithSimilarityVO> getReportByTaskAndUser(Integer uid, Integer taskid) throws IOException {
        Report report = reportMapper.selectByByTaskAndUser(uid,taskid);
        if(report == null)
            return new ResultVO<>(Constant.REQUEST_FAIL, "没有找到对应的报告！");
        return getReportByWorker(report);
    }

    public boolean firstVisitOrNot(Integer reportId){
        boolean firstVisit = false;
        //第一次进入这个方法的时候，向reportVisit里面插入记录
        List<ReportVisit> reportVisit = reportVisitMapper.selectByReportId(reportId);
        System.out.println(reportVisit);
        if(reportVisit == null || reportVisit.size() == 0){   //说明是第一次访问
//            reportVisit = new ReportVisit();
//            reportVisit.setReportId(reportId);
//            reportVisitMapper.insert(reportVisit);
            firstVisit = true;
        }
        return firstVisit;
    }

    public ResultVO<ReportWithSimilarityVO> getReportByWorker(Report report) throws IOException {
        Integer taskid = report.getTaskId();
        Integer uid =report.getUserId();
        //看这个报告全部的图像相似度有没有拿到，如果拿到了，那么就计算文本相似度，然后返回全部的结果
        //下面的方法计算的是report和其他子报告（second）的相似度
        Integer firstId = report.getId();
        List<ReportSimilarityVO> reportSimilarities = new ArrayList<>();
        List<PicSimilarity> picSimilarities = picSimilarityMapper.selectByFirstId(firstId);
        List<Report> tempList = reportMapper.selectOtherReport(taskid,firstId);

        Double picSim = 0.0;
        Double textSim = 0.0;  //全局的文本相似度和图像相似度

        boolean firstVisit = false;

        if(tempList == null || tempList.size() == 0){
            ReportSimilarityVO reportSimilarityVO = new ReportSimilarityVO(firstId,0.0,0.0);
            reportSimilarities.add(reportSimilarityVO);
            //第一份报告一定通过，不用操作
        }
        //不是第一份报告
        else{
            System.out.println(picSimilarities);
            if(picSimilarities.size() == 0)  //查找不到图片相似度，说明要返回
                return new ResultVO<>(Constant.REQUEST_FAIL,"图片相似度仍在计算中",new ReportWithSimilarityVO());
            //拿到了图片相似度，则对于每一个图片相似度计算文字相似度

            //在这之前首先判断需不需要继续计算文本相似度


            TextSimilarityStrategy TFIDFSimilarityStrategy=tfidfStrategy;
            TextSimilarityStrategy SimHash = simHashStrategy;
            for(PicSimilarity picSimilarity: picSimilarities){
                Integer secondId = picSimilarity.getSecondId();
                TextSimilarity textSimilarity = textSimilarityMapper.selectByTwoReportId(firstId,secondId);
                if(textSimilarity.getTexthash() == 0.0 && textSimilarity.getTfdif() == 0.0){
                    //只有第一次进来的时候才需要计算，后面只需要直接拿
                    //如果三个都是0.0的情况前面就已经判断过了，所以这里一定不是第一份报告
                    Report second = reportMapper.selectByPrimaryKey(secondId);
                    Double simHash = SimHash.CalSimilarityOneToOne(report,second);
                    Double tfidf = TFIDFSimilarityStrategy.CalSimilarityOneToOne(report,second);
                    textSimilarity.setTexthash(simHash);
                    textSimilarity.setTfdif(tfidf);
                    System.err.println(textSimilarity.getWord2vec()+" "+textSimilarity.getTfdif()+" "+textSimilarity.getTexthash());
                    textSimilarityMapper.updateByPrimaryKey(textSimilarity);
                }
                //assert断言提前判断有没有错误
                //如果文本相似度tfidf>40，那么就选择取平均值，图片还是照常
                Double minTextSimilarity;
                if(textSimilarity.getTfdif() <= 0.4)
                    minTextSimilarity = textSimilarity.getTfdif();
                else
                    minTextSimilarity = (textSimilarity.getTexthash() + textSimilarity.getTfdif() + textSimilarity.getWord2vec()) / 3;
                Double minPicSimilarity = Math.max(picSimilarity.getHashpic(),Math.max(picSimilarity.getSift(),picSimilarity.getSurf()));

                //TODO 迭代三的内容
                //更新全局最大文本，图像相似度存入，用于后续计算
                picSim = Math.max(picSim,minPicSimilarity);
                textSim = Math.max(textSim,minTextSimilarity);

                ReportSimilarityVO reportSimilarityVO = new ReportSimilarityVO(secondId, minTextSimilarity, minPicSimilarity);
                reportSimilarities.add(reportSimilarityVO);
            }
        }
        synchronized (this) {
            //TODO 迭代三的内容
            //第一次进入这个方法的时候，向reportVisit里面插入记录
            firstVisit = firstVisitOrNot(report.getId());
            //确认上面计算完了，再插入记录
            if (firstVisit) {
                ReportVisit reportVisit = new ReportVisit();
                reportVisit.setReportId(report.getId());
                reportVisitMapper.insert(reportVisit);
            }

            //前端是相似度按照降序排序，因此考虑里面的最大值就可以，也就是上面保留的两个全局变量
            //注意，只有第一次访问报告的时候，才进行下面的逻辑
            if (firstVisit) {
                report.setTextSimilarity(textSim);
                report.setPicSimilarity(picSim);
                boolean pass = true;
                if (textSim > 0.4 || picSim > 0.75)
                    pass = false;
                report.setPass(pass);
                //更新report，把相似度更新进去
                reportMapper.updateByPrimaryKey(report);
                //再更新一下coordinationRanking这张表
                int userid = report.getUserId();
                CoordinationRanking coordinationRanking = coordinationRankingMapper.selectByUserId(userid);
                if (coordinationRanking == null) {  //说明还没有，要插入这个记录
                    coordinationRanking = new CoordinationRanking();
                    coordinationRanking.setUserId(userid);
                    coordinationRanking.setTextSimilarity(textSim);
                    coordinationRanking.setPicSimilarity(picSim);
                    coordinationRanking.setNum(1);
                    coordinationRanking.setTotalSimilarity((textSim + picSim) / 2);
                    coordinationRankingMapper.insert(coordinationRanking);
                } else {
                    Integer num = coordinationRanking.getNum();
                    coordinationRanking.setTextSimilarity((coordinationRanking.getTextSimilarity() * num + textSim) / (num + 1));
                    coordinationRanking.setPicSimilarity((coordinationRanking.getPicSimilarity() * num + picSim) / (num + 1));
                    coordinationRanking.setTotalSimilarity((coordinationRanking.getTextSimilarity() + coordinationRanking.getPicSimilarity()) / 2);
                    coordinationRanking.setNum(num + 1);
                    coordinationRankingMapper.updateByPrimaryKey(coordinationRanking);
                }

                //在这里认为用户完成了一张报告：计算相似度完成认为算是用户完成一份报告
                //如果coordinationAbility表中没有对应条目，那么先插入对应条目
                CoordinationAbility coordinationAbility = coordinationAbilityMapper.selectByUserId(userid);
                if (coordinationAbility == null) {
                    coordinationAbility = new CoordinationAbility();
                    coordinationAbility.setUserId(userid);
                    coordinationAbility.setReportNum(0);
                    coordinationAbility.setBadReportNum(0);
                    coordinationAbility.setModifiedReportNum(0);
                    coordinationAbilityMapper.insert(coordinationAbility);
                }
                //现在已经有了记录，+1就可以
                coordinationAbilityMapper.increaseReportNumByUserid(userid);
                //再根据是否pass，对badReport数目做改动
                if (!pass)
                    coordinationAbilityMapper.increaseBadNumByUserid(userid);
            }
        }

        //将计算出的报告相似度赋值给原来的报告
        String username = userMapper.selectByPrimaryKey(uid).getUsername();
        Task task = taskMapper.selectByPrimaryKey(taskid);
        String type = task.getType();
        String taskname = task.getTaskName();
        ReportVO res = new ReportVO(report);
        res.setTaskname(taskname);
        res.setType(type);
        res.setWorkername(username);
        ReportWithSimilarityVO reportWithSimilarityVO = new ReportWithSimilarityVO(res);
        reportWithSimilarityVO.setReportSimilarities(reportSimilarities);
        System.out.println("结束！");
        return new ResultVO<>(Constant.REQUEST_SUCCESS, "报告返回成功!", reportWithSimilarityVO);
    }


    //从工人已提交报告中获取其领域知识
    List<String> getWorkerReportDomainKnowledge(Integer userId){
        List<Report> reports=reportMapper.selectByUser(userId);
        List<String> res=new ArrayList<>();
        List<Integer> allDf=new ArrayList<>();
        List<Pair<String,Integer>> wordAndDf=new ArrayList<>();
        String src="";
        for(Report report:reports){
            src+=report.getDescription();
            src+=report.getSteps();
        }
        List<Term> words= HanLP.segment(src);
        List<Task> tasks=taskMapper.selectAll();
        HashMap<String,Boolean> mp=new HashMap<>();
        for(Term tm:words){
            if(!tm.nature.equals(Nature.v)&&!tm.nature.equals(Nature.ad)&&!tm.nature.equals(Nature.a)&&!tm.nature.equals(Nature.n)){
                continue;
            }
            String word=tm.word;
            if(mp.get(word))continue;
            mp.put(word,true);
            int df=0;
            for(Task task:tasks){
                TFIDFSimilarity tfidfSimilarity=tfidfSimilarityMapper.selectByWordAndTask(word,task.getId());
                df+=tfidfSimilarity.getFrequency();
            }
            wordAndDf.add(new Pair(word,df));
            allDf.add(df);
        }
        //过滤df太低太高的部分;
        Collections.sort(wordAndDf,(a,b)->a.getValue()-b.getValue());
        int ignorel= (int) Math.floor(allDf.size()*0.05);
        int ignorer= (int) Math.floor(allDf.size()*0.95);
        for(int i=ignorel;i<ignorer;i++)
            res.add(wordAndDf.get(i).getKey());
        return res;
    }

    /**
     * 入口，查询该报告与其他同task报告的相似度
     * @param reportVO
     * @return DuplicateVO，返回两个相似度（文本，图像）并
     */
    @Override
    public ResultVO<DuplicateVO> getReportDuplication(ReportFormVO reportVO,Integer taskid){
        //TODO:策略模式改进
        PictureSimilarityStrategy pictureSimilarityStrategy=new SIFTStrategy();
        TextSimilarityStrategy textSimilarityStrategy=new TFIDFStrategy();


        DuplicateVO res=new DuplicateVO();

        //策略模式实现文本和图像相似度计算
        Double textSimilarity=textSimilarityStrategy.CalcSimilarity(reportVO,taskid);
        Double picSimilarity=pictureSimilarityStrategy.CalcSimilarity(reportVO,taskid);

        res.setTextSimilarity(textSimilarity);
        res.setPicSimilarity(picSimilarity);
        if(textSimilarity>0.9||picSimilarity>0.9)
            res.setPass(false);
        else res.setPass(true);
        return new ResultVO<>(Constant.REQUEST_SUCCESS, "相似度查询成功！", res);
    }

    @Override
    public ResultVO<DuplicateVO> getReportSimilarity(Integer reportId1, Integer reportId2){
        return null;
    }

    //报告协作之插入子报告
    @Override
    public ResultVO<ReportVO> createSubReport(ReportFormVO reportFormVO, Integer fatherid,Integer childid) {
        //这里传入的formVo中的taskid应该是空值，以区分子报告和父报告
        Report report = new Report(reportFormVO);
        report.setSubmitTime(new Date());
        report.setTaskId(null);

        //说明要删除原来的报告
        System.out.println(childid);
        //唯一的区别就是这里需要删除原来的报告，别的没有变化
        if(childid != -1){
//            int taskid = reportMapper.selectByPrimaryKey(childid).getTaskId();
            int res = reportMapper.deleteByPrimaryKey(childid);
            workerMessageMapper.deleteByFromUserIdAndReportId(report.getUserId(),fatherid,childid);
            if(res < 1){
                return new ResultVO<>(Constant.REQUEST_FAIL,"删除原来的报告失败",new ReportVO());
            }
            //删除成功
//            report.setTaskId(taskid);
        }
        int res = reportMapper.insert(report);
        WorkerMessage message=new WorkerMessage();
        Report nowReport=reportMapper.selectByPrimaryKey(fatherid);
        message.setCooReportId(res);
        message.setMessageType(2);
        message.setReportId(nowReport.getId());
        message.setFromRole(1);
        message.setFromUserId(report.getUserId());
        message.setToWorkerId(nowReport.getUserId());
        message.setStatus(0);
        message.setTaskId(nowReport.getTaskId());
        message.setSubmitTime(new Date());
        message.setTaskName(taskMapper.selectByPrimaryKey(nowReport.getTaskId()).getTaskName());
        int messageId=workerMessageMapper.insert(message);
        WebSocketServer.sendMessageToSpecificUser(workerMessageMapper.countStatus(0,message.getToWorkerId()),message.getToWorkerId());
        if(res < 1)
            return new ResultVO<>(Constant.REQUEST_FAIL,"插入报告时出现问题",new ReportVO(report));
        else{
            int sonid = report.getId();
            Coordination coordination = new Coordination(fatherid, sonid);
            res = coordinationMapper.insert(coordination);
            if(res < 1)
                return new ResultVO<>(Constant.REQUEST_FAIL,"插入协作关系时出现问题",new ReportVO(report));
            Date nowTime = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String nowDate = sdf.format(nowTime);
            Activity loginRecord=activityMapper.selectByUserIdAndLoginDate(reportFormVO.getWorkerid(),nowDate);
            activityMapper.increaseActivityByUserid(reportFormVO.getWorkerid(),2,nowDate);
            //向协作能力里面插入
            //如果coordinationAbility表中没有对应条目，那么先插入对应条目
            Integer userid = report.getUserId();
            CoordinationAbility coordinationAbility = coordinationAbilityMapper.selectByUserId(userid);
            if (coordinationAbility == null) {
                coordinationAbility = new CoordinationAbility();
                coordinationAbility.setUserId(userid);
                coordinationAbility.setReportNum(0);
                coordinationAbility.setBadReportNum(0);
                coordinationAbility.setModifiedReportNum(0);
                coordinationAbilityMapper.insert(coordinationAbility);
            }
            //现在已经有了记录，+1就可以
            coordinationAbilityMapper.increaseReportNumByUserid(userid);
            return new ResultVO<>(Constant.REQUEST_SUCCESS,"插入子报告成功",new ReportVO(report));
        }
    }

    //修改提交了但是没有通过相似度审查的主报告
    @Override
    public ResultVO<ReportVO> modifyReport(ReportFormVO reportFormVO, Integer reportid) {
        int res = reportMapper.deleteByPrimaryKey(reportid);
        if(res < 1){
            return new ResultVO<>(Constant.REQUEST_FAIL,"删除失败！",new ReportVO());
        }
        //修改报告的时候这个coordinationAbility里面一定已经有了目录，所以肯定能找出来，然后直接修改对应的数值就可以
        coordinationAbilityMapper.increaseModifiedNumByUserid(reportFormVO.getWorkerid());
        //后续逻辑和插入报告一样
        return createReport(reportFormVO);
    }

    @Override
    public ResultVO<DuplicateVO> getReportSimilarityList(Integer reportId) {
        return null;
    }

    @Override
    public ResultVO<List<SubReportInfoVO>> getSubReportList(Integer reportId) {
        List<Coordination> coordinationList = coordinationMapper.selectByFatherId(reportId);
        if(coordinationList == null)
            return new ResultVO<>(Constant.REQUEST_FAIL,"获取子报告列表失败",new ArrayList<>());
        List<SubReportInfoVO> res = new ArrayList<>();
        for(Coordination coordination: coordinationList){
            Integer sonId = coordination.getChildrenId();
            Integer userid = reportMapper.selectByPrimaryKey(sonId).getUserId();
            String username = userMapper.selectByPrimaryKey(userid).getUsername();
            SubReportInfoVO subReportInfoVO = new SubReportInfoVO(sonId, username);
            res.add(subReportInfoVO);
            //res.add(subReportInfoVO);
        }
        return new ResultVO<>(Constant.REQUEST_SUCCESS,"查询子报告列表成功",res);
    }

    //TODO 返回userid对应工人和现在时间距离interval（单位：天）的提交报告次数
    //可选的选项有1，3，7，30，60分别对应过去一天，过去3天，过去一周，过去一个月和过去两个月
    //不是这些数值的，默认返回一周之内的数值
    //需要的话可以再添加别的取值，我加两行代码就行

    public Integer getActiveness(Integer interval, Integer userId){
        System.out.println(interval);
        return reportMapper.getIntervalReportNum(interval, userId);
    }

    //TODO 返回userid对应工人距离现在最近一次提交
    public Date lastReportSubmit(Integer userId){
        return reportMapper.getLastSubmit(userId);
    }


}

